package com.handpay.zztong.hp.balancequery.model;

import com.handpay.framework.fastjson.FastJsonHelper;
import com.handpay.zztong.hp.balancequery.bean.MicroBalanceQueryBean;
import com.handpay.zztong.hp.base.activity.ZZTongActivity;
import com.handpay.zztong.hp.base.callback.BusinessEngineListener;
import com.handpay.zztong.hp.base.model.base.BaseModel;
import com.handpay.zztong.hp.config.HttpUrlConstant;

import java.util.Hashtable;

/**
 * @author sxshi on 2017/5/2.
 *         email:emotiona_xiaoshi@126.com
 *         describe:Describe the function  of the current class
 */

public class QueryBanlanceModel extends BaseModel {
    private ZZTongActivity mContext;

    public QueryBanlanceModel(ZZTongActivity mContext) {
        this.mContext = mContext;
    }

    private BusinessEngineListener<MicroBalanceQueryBean> mBusinessEngineListener;

    /**
     * query balance
     *
     * @param paramers               request paramers
     * @param businessEngineListener callback listener
     */
    public void queryBanlance(Hashtable<String, String> paramers, BusinessEngineListener<MicroBalanceQueryBean> businessEngineListener) {
        this.mBusinessEngineListener = businessEngineListener;
        doPost(mContext, HttpUrlConstant.Do_BalanceEnquiry20, paramers);
    }


    @Override
    public boolean netResponse(String action, byte[] data) {
        if (super.netResponse(action, data)) return true;
        if (action.equals(HttpUrlConstant.Do_BalanceEnquiry20)) {
            MicroBalanceQueryBean balanceQueryBean = new MicroBalanceQueryBean();
            if (data_type == DATA_TYPE.DATA_TYPE_JSON) {
                balanceQueryBean = FastJsonHelper.getObject(new String(data), MicroBalanceQueryBean.class);
            }
            if (mBusinessEngineListener != null) mBusinessEngineListener.callbackBusinessResponse(balanceQueryBean);
        }
        return false;
    }

}
